package com.itfitness.lifecycledemo;

import androidx.appcompat.app.AppCompatActivity;
import androidx.lifecycle.LifecycleObserver;

import android.content.Intent;
import android.os.Bundle;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {
    private Button bt_start,bt_stop;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        VideoPlayer videoPlayer = new VideoPlayer();
        //添加监听者
        getLifecycle().addObserver(videoPlayer);


        //开启和结束服务
        bt_start = findViewById(R.id.bt_start);
        bt_stop = findViewById(R.id.bt_stop);
        final Intent intent = new Intent(this, MyService.class);
        bt_start.setOnClickListener(v->{
            startService(intent);
        });
        bt_stop.setOnClickListener(v->{
            stopService(intent);
        });
    }
}